<?

//Data loading
if (GetParam("m","")=="AUDIT")
    $title='BALANCE SHEET (AUDIT)';
else
    $title='BALANCE SHEET';
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = 'PT. AMPEL JAYA';

$page   = 'PAGE';
$DEFINE_FONT=0;
$pdf=new COAPDFReport("P","mm","Letter");

$pdf->DBConnection($DBConnection->dbc);
$pdf->Period(GetParam("y",""),GetParam("m",""));
$pdf->AddPage();
$pdf->GenerateReport();
$pdf->Output();

class COAPDFReport extends PDF {
  function COAPDFReport($Page,$Size,$PageMode) {
    parent::PDF($Page,$Size,$PageMode);
    $this->ColumnSize = array(85,30,30,30,30);
    $this->TableName = "tblcoa";
    $this->AddFont('arialn','','arialn.php');
    $this->SetFont('arialn','',10);
    $this->SetLeftMargin(5);
  }

  function DBConnection ($Conn) {
    $this->DBConnection = $Conn;
  }

  function WriteLine($Results) {
    foreach ($Results as $Line) {
      for ($x=0;$x<count($Line["M"]);$x++) {
      if (count($Line["M"]))
        $this->Cell($Line["C"][$x],5,$Line["M"][$x],$Line["B"][$x],0,$Line["O"][$x],0);
      }
      if (count($Line["M"]))
      $this->Ln();
    }
  }

  function Header() {
    global $DBGeneral;
    $title = "BALANCE SHEET";
    $page   = 'HAL';
    $title .= (GetParam("m","")=="13")?' (AUDIT)':"";
    $perush = (GetParam("office",""))?GetCompany (GetParam("office","")):'PT. AMPEL JAYA';

      $this->SetFont('arialn','',10);
    $Periode = (GetParam("m","")=="13")?$this->BuildPeriod (GetParam("y",""), 12):$this->BuildPeriod (GetParam("y",""), GetParam("m",""));
    //Header Configuration
    $this->HeaderAttribute[0]["M"] = array($perush);
    $this->HeaderAttribute[0]["C"] = array(200);
    $this->HeaderAttribute[0]["O"] = array("C");

    $this->HeaderAttribute[1]["M"] = array($title);
    $this->HeaderAttribute[1]["C"] = array(200);
    $this->HeaderAttribute[1]["O"] = array("C");

    $this->HeaderAttribute[2]["M"] = array("AS OF: ".$Periode);
    $this->HeaderAttribute[2]["C"] = array(200);
    $this->HeaderAttribute[2]["O"] = array("C");

    $this->WriteLine($this->HeaderAttribute);

  }

  function GenerateReport(){
        $SQL = "
            SELECT skada,namacc,parent,printing,jumlah,group_name,coatype,{$this->_LSMonth},{$this->_SMonth}
            FROM tblcoa, tblcoagroup
            WHERE ifnull(parent,'')='' AND
        (coatype='ASSETS' OR coatype='LIABILITIES' OR coatype='EQUITY') AND
        tblcoa.grup=tblcoagroup.group_id AND ledger='{$this->_CYear}'
        ";
      if (GetParam("office",""))      $SQL .= " AND tblcoa.ktrasl='".GetParam("office","")."'";
      die($SQL);
      $LeftIdx=count($this->LeftTree);
      $RightIdx=count($this->RightIdx);
    $MyResult = $this->DBConnection->get_results($SQL,ARRAY_A);
    if ($MyResult) {
        foreach ($MyResult as $RowResult) {
            if ($RowResult["coatype"]=="ASSETS") {
                $this->LeftTree[$LeftIdx]["description"] = $RowResult["namacc"];
                $LeftIdx=count($this->LeftTree);

                //GetCOAList ($Space."  ", $RowResult["skada"], GetParam("m",""), "L");

                $LeftTree[$LeftIdx]["description"] = "TOTAL ".$RowResult["namacc"];
                $LeftTree[$LeftIdx]["akumulasi"]   = $RowResult["akumulasi"];
                $LeftTree[$LeftIdx]["lastakumulasi"] = $RowResult["lastakumulasi"];


                $LeftTree[$LeftIdx]["printing"]  = 1;
                $LeftTree[$LeftIdx]["total"]     = 1;
                $LeftIdx++;
                $LeftIdx++;
            } elseif (($RowResult["coatype"]=="LIABILITIES") || ($RowResult["coatype"]=="EQUITY")) {
                $RightTree[$RightIdx]["description"] = $RowResult["namacc"];
                $RightIdx++;
                //GetCOAList ($Space."  ", $RowResult["skada"], GetParam("m",""), "R");
                $RightTree[$RightIdx]["description"] = "TOTAL ".$RowResult["namacc"];
                $RightTree[$RightIdx]["akumulasi"]   = $RowResult["akumulasi"];
                $RightTree[$RightIdx]["lastakumulasi"]   = $RowResult["lastakumulasi"];



                $RightTree[$RightIdx]["printing"]    = 1;
                                  $RightTree[$RightIdx]["total"]    = 1;
                $RightIdx++;
                $RightIdx++;
            }

        }

    }
      //$this->WriteLine($Records);
  }

  function BuildPeriod ($year, $month) {
    $arraymonth = array("","JANUARI","FEBRUARI","MARET","APRIL","MEI","JUNI","JULI","AGUSTUS","SEPTEMBER","OKTOBER","NOPEMBER","DESEMBER");
    return strtoupper(date("d ", mktime(0, 0, 0, $month+1, 0, $year))).$arraymonth[$month].strtoupper(date(" Y", mktime(0, 0, 0, $month+1, 0, $year)));
  }

  function Period($Year, $Month){
    if ($Month<10) $Month = "0".$Month;
    if (($Month-1)<10) {$LMonth="0".($Month-1);}
    else $LMonth=$Month-1;
    $this->_CYear  = $Year;
    $this->_CMonth = $Month;
    $this->_SMonth = "aku".$Month;
    if ($Month==1) $this->_LSMonth = "awal";
    else $this->_LSMonth = "aku".$LMonth;
  }

  function WriteRow($parent_skada,$inverse) {

  }


function SummarizeParent () {
    global $LeftTree, $RightTree, $DBConnection, $LeftIdx, $RightIdx;

    if (!$LeftIdx)  $LeftIdx  = 0;
    if (!$RightIdx) $RightIdx = 0;
    $SQL = "
        SELECT skada,namacc,pathprn,parent,printing,jumlah,group_name,coatype,lastakumulasi,akumulasi
        FROM tblcoa_totaltmp, tblcoagroup
        WHERE parent='' AND
    (coatype='ASSETS' OR coatype='LIABILITIES' OR coatype='EQUITY') AND
    tblcoa_totaltmp.grup=tblcoagroup.group_id
    ";
  if (GetParam("office",""))      $SQL .= " AND tblcoa_totaltmp.ktrasl='".GetParam("office","")."'";


    //print $SQL."<p>\n";die();
    $MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);
    if ($MyResult) {
        foreach ($MyResult as $RowResult) {
            if ($RowResult["coatype"]=="ASSETS") {

                $LeftTree[$LeftIdx]["description"] = $RowResult["namacc"];
                $LeftIdx++;

                GetCOAList ($Space."  ", $RowResult["skada"], GetParam("m",""), "L");

                $LeftTree[$LeftIdx]["description"] = "TOTAL ".$RowResult["namacc"];
                $LeftTree[$LeftIdx]["akumulasi"]   = $RowResult["akumulasi"];
                $LeftTree[$LeftIdx]["lastakumulasi"]   = $RowResult["lastakumulasi"];


                $LeftTree[$LeftIdx]["printing"]    = 1;
                $LeftTree[$LeftIdx]["total"]    = 1;
                $LeftIdx++;
                $LeftIdx++;
            } elseif (($RowResult["coatype"]=="LIABILITIES") || ($RowResult["coatype"]=="EQUITY")) {
                $RightTree[$RightIdx]["description"] = $RowResult["namacc"];
                $RightIdx++;
                GetCOAList ($Space."  ", $RowResult["skada"], GetParam("m",""), "R");
                $RightTree[$RightIdx]["description"] = "TOTAL ".$RowResult["namacc"];
                $RightTree[$RightIdx]["akumulasi"]   = $RowResult["akumulasi"];
                $RightTree[$RightIdx]["lastakumulasi"]   = $RowResult["lastakumulasi"];



                $RightTree[$RightIdx]["printing"]    = 1;
                                $RightTree[$RightIdx]["total"]    = 1;
                $RightIdx++;
                $RightIdx++;
            }

        }

    }
}

}
/*

function CreateDummyCOA () {
    global $DBConnection;

    //$TEMP = "TEMPORARY";

    $Year   = GetParam("y","");
    $LastYear = $Year-1;
    $Month  = GetParam("m","");
    if ($Month=="AUDIT") $Month=13;
    if ($Month<10) $Month = "0".$Month;
    if (($Month-1)<10) $LastMonth = "0".($Month-1);

    if ($Month<2) $LastMonth = "awal as lastmonth";
    else {$LastMonth = "aku".$LastMonth." as lastmonth";}

    $Mutasi = "(mutd".$Month."-"."mutk".$Month.") as mutasi";
    $CurrentMonth = "aku".$Month." as cmonth";

    $SQL = "DROP TABLE IF EXISTS `tblcoatmp`";
    $DBConnection->dbc->query($SQL);

    $SQL = "DROP TABLE IF EXISTS `tblcoatmp_last`";
    $DBConnection->dbc->query($SQL);

    $SQL = "
        CREATE $TEMP TABLE `tblcoatmp` (
        `skada` VARCHAR( 64 ) NOT NULL,
        `pathprn` VARCHAR( 64 ) NOT NULL,
        `namacc` VARCHAR( 64 ) NOT NULL,
        `parent` VARCHAR( 24 ) NOT NULL,
        `printing` tinyint( 4 ) NOT NULL,
        `jumlah` tinyint( 4 ) NOT NULL,
        `grup` tinyint( 4 ) NOT NULL,
        `akumulasi` decimal( 16,4) NOT NULL,
        `lastakumulasi` decimal( 16,4) NOT NULL,
        `ktrasl` VARCHAR( 4 ) NOT NULL
        );
    ";
    $DBConnection->dbc->query($SQL);

    $SQL = "
        CREATE $TEMP TABLE `tblcoatmp_last` (
        `skada` VARCHAR( 64 ) NOT NULL,
        `akumulasi` decimal( 16,4) NOT NULL,
        `ktrasl` VARCHAR( 4 ) NOT NULL
        );
    ";
    $DBConnection->dbc->query($SQL);

    $SQL = "
        INSERT INTO tblcoatmp_last
        SELECT skada, $LastMonth, ktrasl
        FROM tblcoa WHERE tipe=1 AND ledger='$Year'
    ";

    if (GetParam("office",""))  $SQL .= "AND tblcoa.ktrasl='".GetParam("office","")."'";
    $DBConnection->dbc->query($SQL);

    $SQL = "
        INSERT INTO tblcoatmp
        SELECT tblcoa.skada, tblcoa.pathprn, tblcoa.namacc, tblcoa.parent, tblcoa.printing, tblcoa.jumlah, tblcoa.grup, $CurrentMonth, tblcoatmp_last.akumulasi, tblcoa.ktrasl
        FROM tblcoa LEFT JOIN tblcoatmp_last ON tblcoatmp_last.skada=tblcoa.skada AND tblcoatmp_last.ktrasl=tblcoa.ktrasl
        WHERE tipe=1 AND ledger='$Year'
    ";

    if (GetParam("office","")) $SQL .= "AND tblcoa.ktrasl='".GetParam("office","")."'";
    $DBConnection->dbc->query($SQL);

    $SQL = "DROP TABLE IF EXISTS `tblcoa_totaltmp`";
    $DBConnection->dbc->query($SQL);

    $SQL = "
        CREATE $TEMP TABLE `tblcoa_totaltmp` (
        `skada` VARCHAR( 64 ) NOT NULL,
        `pathprn` VARCHAR( 64 ) NOT NULL,
        `namacc` VARCHAR( 64 ) NOT NULL,
        `parent` VARCHAR( 24 ) NOT NULL,
        `printing` tinyint( 4 ) NOT NULL,
        `jumlah` tinyint( 4 ) NOT NULL,
        `grup` tinyint( 4 ) NOT NULL,
        `akumulasi` decimal( 16,4) NOT NULL,
        `lastakumulasi` decimal( 16,4) NOT NULL,
        `ktrasl` VARCHAR( 4 ) NOT NULL
        );
    ";
    $DBConnection->dbc->query($SQL);

    $SQL  = "
        INSERT INTO tblcoa_totaltmp
        SELECT tblcoatmp.skada, tblcoatmp.pathprn, tblcoatmp.namacc, tblcoatmp.parent, tblcoatmp.printing,
        tblcoatmp.jumlah, tblcoatmp.grup, sum(aku$Month), lastakumulasi, tblcoa.ktrasl
        FROM tblcoatmp, tblcoa
        WHERE tblcoa.pathprn like concat(tblcoatmp.pathprn,'%') AND tblcoatmp.ktrasl=tblcoa.ktrasl
    ";

    if (GetParam("office","")) $SQL .= " AND tblcoa.ktrasl='".GetParam("office","")."' ";

    $SQL .= " GROUP BY tblcoatmp.skada  ";
        //print $SQL."<p>\n";die();
    $DBConnection->dbc->query($SQL);
}

function SumAsset ($isLast) {
    global $DBConnection;
      if ($isLast) {
    $SQL = "
        SELECT sum(lastakumulasi)
        FROM tblcoa_totaltmp, tblcoagroup
        WHERE parent='' AND (coatype='ASSETS') AND tblcoa_totaltmp.grup=tblcoagroup.group_id
    ";

      } else {
    $SQL = "
        SELECT sum(akumulasi)

        FROM tblcoa_totaltmp, tblcoagroup
        WHERE parent='' AND
                (coatype='ASSETS') AND
                tblcoa_totaltmp.grup=tblcoagroup.group_id
    ";
      }
      if (GetParam("office","")) $SQL .= " AND ktrasl='".GetParam("office","")."' ";
      return $DBConnection->dbc->get_var($SQL);

}

function SumEquity ($isLast) {
    global $DBConnection;
      if ($isLast) {
    $SQL = "
        SELECT sum(lastakumulasi*-1)

        FROM tblcoa_totaltmp, tblcoagroup
        WHERE parent='' AND
                (coatype='LIABILITIES' OR coatype='EQUITY') AND
                tblcoa_totaltmp.grup=tblcoagroup.group_id
    ";

      } else {
    $SQL = "
        SELECT sum(akumulasi*-1)

        FROM tblcoa_totaltmp, tblcoagroup
        WHERE parent='' AND
                (coatype='LIABILITIES' OR coatype='EQUITY') AND
                tblcoa_totaltmp.grup=tblcoagroup.group_id
    ";
      }
      if (GetParam("office","")) $SQL .= " AND ktrasl='".GetParam("office","")."' ";
      return $DBConnection->dbc->get_var($SQL);

}



function SummarizeParent () {
    global $LeftTree, $RightTree, $DBConnection, $LeftIdx, $RightIdx;

    if (!$LeftIdx)  $LeftIdx  = 0;
    if (!$RightIdx) $RightIdx = 0;
    $SQL = "
        SELECT skada,namacc,pathprn,parent,printing,jumlah,group_name,coatype,lastakumulasi,akumulasi
        FROM tblcoa_totaltmp, tblcoagroup
        WHERE parent='' AND
    (coatype='ASSETS' OR coatype='LIABILITIES' OR coatype='EQUITY') AND
    tblcoa_totaltmp.grup=tblcoagroup.group_id
    ";
  if (GetParam("office",""))      $SQL .= " AND tblcoa_totaltmp.ktrasl='".GetParam("office","")."'";

  $SQL = "SELECT skada,namacc,pathprn,parent,printing,jumlah,group_name,coatype";
    //print $SQL."<p>\n";die();
    $MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);
    if ($MyResult) {
        foreach ($MyResult as $RowResult) {
            if ($RowResult["coatype"]=="ASSETS") {

                $LeftTree[$LeftIdx]["description"] = $RowResult["namacc"];
                $LeftIdx++;

                GetCOAList ($Space."  ", $RowResult["skada"], GetParam("m",""), "L");

                $LeftTree[$LeftIdx]["description"] = "TOTAL ".$RowResult["namacc"];
                $LeftTree[$LeftIdx]["akumulasi"]   = $RowResult["akumulasi"];
                $LeftTree[$LeftIdx]["lastakumulasi"]   = $RowResult["lastakumulasi"];


                $LeftTree[$LeftIdx]["printing"]    = 1;
                $LeftTree[$LeftIdx]["total"]    = 1;
                $LeftIdx++;
                $LeftIdx++;
            } elseif (($RowResult["coatype"]=="LIABILITIES") || ($RowResult["coatype"]=="EQUITY")) {
                $RightTree[$RightIdx]["description"] = $RowResult["namacc"];
                $RightIdx++;
                GetCOAList ($Space."  ", $RowResult["skada"], GetParam("m",""), "R");
                $RightTree[$RightIdx]["description"] = "TOTAL ".$RowResult["namacc"];
                $RightTree[$RightIdx]["akumulasi"]   = $RowResult["akumulasi"];
                $RightTree[$RightIdx]["lastakumulasi"]   = $RowResult["lastakumulasi"];



                $RightTree[$RightIdx]["printing"]    = 1;
                                $RightTree[$RightIdx]["total"]    = 1;
                $RightIdx++;
                $RightIdx++;
            }

        }

    }
}

function GetCOAList ($Space, $SkadaParent,$month,$orientation) {
    global $DBConnection, $LeftTree, $RightTree, $LeftIdx, $RightIdx;
    if ($month<10) $month = "0".intval($month);

    if (!$LeftIdx)  $LeftIdx  = 0;
    if (!$RightIdx) $RightIdx = 0;
    $SQL = "
        SELECT skada, namacc, pathprn, parent, printing, jumlah, group_name, coatype, akumulasi
        FROM tblcoa_totaltmp,tblcoagroup
        WHERE parent='$SkadaParent' AND tblcoa_totaltmp.grup=tblcoagroup.group_id AND printing=1
        ";
        if (GetParam("office",""))      $SQL .= " AND tblcoa_totaltmp.ktrasl='".GetParam("office","")."'";

    //print $SQL."<br>\n\n";die();
    $MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);

    if ($MyResult){
        foreach ($MyResult as $RowResult) {
            if ($orientation=="L")  {
                $LeftTree[$LeftIdx]["description"] = $Space.$RowResult["namacc"];
                $LeftTree[$LeftIdx]["akumulasi"]   = $RowResult["akumulasi"];
                $LeftTree[$LeftIdx]["lastakumulasi"]   = $RowResult["lastakumulasi"];
                $LeftTree[$LeftIdx]["printing"]    = $RowResult["printing"];
                $LeftTree[$LeftIdx]["jumlah"]      = $RowResult["jumlah"];

//              print "LEFT:   ". $LeftTree[$LeftIdx]["description"]." ".$LeftTree[$LeftIdx]["total"]."<p>\n";
                $LeftIdx++;
                GetCOAList ($Space."  ",  $RowResult["skada"], $month, "L");
            } else {
                $RightTree[$RightIdx]["description"] = $Space.$RowResult["namacc"];
                $RightTree[$RightIdx]["akumulasi"]   = $RowResult["akumulasi"];
                $RightTree[$RightIdx]["lastakumulasi"]   = $RowResult["lastakumulasi"];
                $RightTree[$RightIdx]["printing"]    = $RowResult["printing"];
                $RightTree[$RightIdx]["jumlah"]      = $RowResult["jumlah"];

//              print "RIGHT:    ".$RightTree[$RightIdx]["description"]." ".$RightTree[$RightIdx]["total"]."<p>\n";
                $RightIdx++;
                GetCOAList ($Space."  ",  $RowResult["skada"], $month, "R");

            }
        }
    }
}

function BuildPeriod ($year, $month) {
  $arraymonth = array("","JANUARI","FEBRUARI","MARET","APRIL","MEI","JUNI","JULI","AGUSTUS","SEPTEMBER","OKTOBER","NOPEMBER","DESEMBER");
  return strtoupper(date("d F Y", mktime(0, 0, 0, $month+1, 0, $year)));

}

class COAPDFReport extends PDF {

    function Header() {
        global $title,$perush,$page,$DEFINE_FONT;
        if ($DEFINE_FONT==0) {
            $this->AddFont('arialn','','arialn.php');
            $DEFINE_FONT=1;
        }

        $this->SetFont('arialn','',10);
        $this->Cell(200,5,$perush,0,1,'C',0);
        $this->Cell(200,5,$title,0,1,'C',0);
        $this->Cell(200,5,"AS OF: ".BuildPeriod (GetParam("y",""), GetParam("m","")),0,1,'C',0);
        $this->Cell(200,5,$page." ".$this->PageNo(),0,1,'R',0);
        //Header

        //Column widths
        $w=array(51,25,25,51,25,25);
        $this->SetFont('arialn','',8);
        $this->Cell($w[0],5,"ASSET",1,0,'C',0);
        $this->Cell($w[1],5,"CURR. MONTH",1,0,'C',0);
        $this->Cell($w[2],5,"LAST MONTH",1,0,'C',0);
        $this->Cell($w[3],5,"LIABILITIES & EQUITY",1,0,'C',0);
        $this->Cell($w[4],5,"CURR. MONTH",1,0,'C',0);
        $this->Cell($w[5],5,"LAST MONTH",1,0,'C',0);

        $this->Ln();
        $this->SetFont('arialn','',7);
    }

    function COATable() {
        global $LeftTree, $RightTree, $LeftIdx, $RightIdx;
        //Column widths
        $w=array(1,50,24,1,24,1);
        //Data
        if ($LeftIdx>$RightIdx) $counter = $LeftIdx-2;
        else $counter = $RightIdx-2;

        for ($x=0;$x<=$counter;$x++)
        {

            $LDesc = $LeftTree[$x]["description"];
            if ($LeftTree[$x]["printing"]==1) {

                if ($LeftTree[$x]["akumulasi"]<0) {
                    $LeftTree[$x]["akumulasi"] = $LeftTree[$x]["akumulasi"]*-1;
                    $LTot  = "(".number_format($LeftTree[$x]["akumulasi"]).")";
                } else {
                    $LTot  = number_format($LeftTree[$x]["akumulasi"]);
                }

                if ($LeftTree[$x]["lastakumulasi"]<0) {
                    $LeftTree[$x]["lastakumulasi"] = $LeftTree[$x]["lastakumulasi"]*-1;
                    $LLTot  = "(".number_format($LeftTree[$x]["lastakumulasi"]).")";
                } else {
                    $LLTot  = number_format($LeftTree[$x]["lastakumulasi"]);
                }


            } else {
                $LTot  = "";
                $LLTot  = "";
            }

                if ($LeftTree[$x]["total"]==1) {
                  $this->Cell($w[0],4,"",'LBT',0,'L',0);
                  $this->Cell($w[1],4,$LDesc,'BTR',0,'L',0);
                  $this->Cell($w[2],4,$LTot,'BT',0,'R',0);
                  $this->Cell($w[3],4,"",'BT',0,'L',0);
                  $this->Cell($w[4],4,$LLTot,'LBT',0,'R',0);
                  $this->Cell($w[5],4,"",'BTR',0,'R',0);
                } else {
                  $this->Cell($w[0],4,"",'L',0,'L',0);
                  $this->Cell($w[1],4,$LDesc,'R',0,'L',0);
                  $this->Cell($w[2],4,$LTot,0,0,'R',0);
                  $this->Cell($w[3],4,"",'R',0,'L',0);
                  $this->Cell($w[4],4,$LLTot,0,0,'R',0);
                  $this->Cell($w[5],4,"",'R',0,'L',0);
                }
            $RDesc = $RightTree[$x]["description"];
            if ($RightTree[$x]["printing"]==1) {
                if ($RightTree[$x]["akumulasi"]<>0)
                    $RightTree[$x]["akumulasi"] = $RightTree[$x]["akumulasi"]*-1;

                if ($RightTree[$x]["akumulasi"]<0) {
                    $RTot  = "(".number_format($RightTree[$x]["akumulasi"]*-1).")";
                } else {
                    $RTot  = number_format($RightTree[$x]["akumulasi"]);
                }

                if ($RightTree[$x]["lastakumulasi"]<0) {
                    $RLTot  = "(".number_format($RightTree[$x]["lastakumulasi"]*-1).")";
                } else {
                    $RLTot  = number_format($RightTree[$x]["lastakumulasi"]);
                }

            } else {
                $RTot  = "";
                $RLTot  = "";
            }

                if ($RightTree[$x]["total"]==1) {
                  $this->Cell($w[0],4,"",'LBT',0,'L',0);
                  $this->Cell($w[1],4,$RDesc,'BTR',0,'L',0);
                  $this->Cell($w[2],4,$RTot,'BT',0,'R',0);
                  $this->Cell($w[3],4,"",'BT',0,'L',0);
                  $this->Cell($w[4],4,$RLTot,'LBT',0,'R',0);
                  $this->Cell($w[5],4,"",'BTR',0,'R',0);
                } else {
                  $this->Cell($w[0],4,"",'L',0,'L',0);
                  $this->Cell($w[1],4,$RDesc,'R',0,'L',0);
                  $this->Cell($w[2],4,$RTot,0,0,'R',0);
                  $this->Cell($w[3],4,"",'R',0,'L',0);
                  $this->Cell($w[4],4,$RLTot,0,0,'R',0);
                  $this->Cell($w[5],4,"",'R',0,'L',0);
                }
            $this->Ln();
        }
        $this->Cell(202,0,'','T');
        $this->Ln();
      $this->Cell($w[0],5,"",'L',0,'L',0);
        $this->Cell($w[1],5,"TOTAL ASSET:",'R',0,'L',0);
        $this->Cell($w[2],5,number_format(SumAsset(0)),0,0,'R',0);
        $this->Cell($w[3],5,"",'R',0,'L',0);
        $this->Cell($w[4],5,number_format(SumAsset(1)),0,0,'R',0);
        $this->Cell($w[5],5,"",'R',0,'L',0);

      $this->Cell($w[0],5,"",'L',0,'L',0);
        $this->Cell($w[1],5,"TOTAL LIABILITIES & EQUITY:",'R',0,'L',0);
        $this->Cell($w[2],5,number_format(SumEquity(0)),0,0,'R',0);
        $this->Cell($w[3],5,"",'R',0,'L',0);
        $this->Cell($w[4],5,number_format(SumEquity(1)),0,0,'R',0);
        $this->Cell($w[5],5,"",'R',0,'L',0);

        $this->Ln();

        //Closure line
        //$this->Cell(array_sum($w),0,'','T');
    }

    function Footer() {
        //Closure line
        $this->Cell(202,0,'','T');
    }

}
*/
?>
